<template>
  <div>
    <el-table
      :data="menulist"
      border
      default-expand-all
      row-key="id"
      :tree-props="{ children: 'children' }"
      style="width: 100%"
      class="table"
    >
      <el-table-column prop="id" label="菜单编号" width="180"> </el-table-column>
      <el-table-column prop="title" label="菜单名称" width="180"> </el-table-column>
      <el-table-column prop="pid" label="上级菜单"> </el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="item">
          <div>
            <i :class="item.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <!-- <el-button type="success" plain size="mini"> -->
        <!-- item.row 代表的表哥的每一行 -->
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
        <!-- </el-button> -->
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button type="primary" size="mini" plain @click="edit(item.row.id)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              icon="el-icon-delete"
              circle
              size="mini"
              @click="del(item.row.id)"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
// 引入接口
import { menuList, menuDelete } from "../../request/api.js";
// 辅助函数
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      // tableData: [],
    };
  },
  methods: {
    ...mapActions({
      getMenuList: "menu/getMenuListActions",
    }),
    // 删除
    del(id) {
      // console.log('删除中');
      this.$confirm("你确定要离开我么", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // console.log(id,123);
          // 调用删除接口
          menuDelete({
            id,
          }).then((res) => {
            // console.log(res);
            if (res.code == 200) {
              this.$message.success(res.msg);
              // 重新调用
              this.getMenuList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 编辑
    edit(id) {
      // 告诉父组件打开弹框
      this.$emit("edit", id);
    },
  },
  mounted() {
    // console.log(this.$store,'仓库');
    menuList().then((res) => {
      // console.log(res);
      this.tableData = res.list;
    });
    this.getMenuList();
  },
  watch: {},
  computed: {
    ...mapGetters({
      menulist: "menu/getMenu",
    }),
  },
  filters: {},
  components: {},
};
</script>
<style scoped>
.table {
  margin-top: 10px;
}
</style>
